/**
 * \file CClientFrm.h
 * \author Corentin Le Bail
 * \date 2009-2012
 * \brief Fichier de déclaration de la class CClientFrm
 */
//------------------------------------------------------------------------------
#ifndef __CCLIENTFRM_H__
#define __CCLIENTFRM_H__
//------------------------------------------------------------------------------
#include "CMyMainWindow.h"
#include "CMainFrm.h"
#include "ui_CClientFrm.h"
#include "CGrilleWidget.h"
#include "CTextRevWidget.h"
//------------------------------------------------------------------------------
/**
 * \class CClientFrm CClientFrm.h "CClientFrm.h"
 * \brief Classe de la fenêtre des clients.
 */
class CClientFrm : public CMyMainWindow, private Ui::ClientFrm {
	Q_OBJECT
	public:
		/**
		 * \fn CClientFrm(QString name, QString lastCode, CMainFrm *parent = 0)
		 * \brief Constructeur
		 * \param[in] name Nom de l'objet
		 * \param[in] lastCode Dernier code traité
		 * \param[in] parent Référence vers un objet parent
		 */
		CClientFrm(QString name, QString lastCode, CMainFrm *parent = 0);
	private:
		enum {cnacNum, cnacAction, cnacDate, cnacHeure, cnacQui, cnacInterloc, cnacCommentaires} EColActionsClientNames;
		enum {cnccNum, cnccDefaut, cnccNom, cnccFonction, cnccTel, cnccFax, cnccMail} EColContactClientNames;
		enum {cnadcNum, cnadcNom, cnadcAdresse1, cnadcAdresse2, cnadcAdresse3, cnadcCodePostal, cnadcVille, cnadcPays, cnadcDistance} EColAdressesClientNames;
		enum {cndcNum, cndcTitre, cndcDate, cndcPar, cndcMontant, cndcStatus, cndcCommande, cndcBL, cndcFactures} EColDevisClientNames;
		enum {cncocNom, cncocDate, cncocDevis, cncocMontant, cncocBL, cncocFactures} EColCommandesClientNames;
		enum {cnbcNom, cnbcDate, cnbcDevis, cnbcCommande, cnbcFacture, cnbcMontant} EColBLsClientNames;
		enum {cnfcNum, cnfcDate, cnfcEcheance, cnfcDevis, cnfcCommande, cnfcBL, cnfcMontant} EColFacturesClientNames;
		enum {cnpaNum, cnpaArticle, cnpaPrix} EColPrixArticleClientNames;
		enum {cnpdNum, cnpdDescription, cnpdDocument} EColDocuments;
		enum {cnecNum, cnecAction, cnecDescription, cnecDate, cnecRepete, cnecDestinataire, cnecMail, cnecCmtr} EColEcheancesClient;
		enum {cnmcNum, cnmcRefMat, cnmcDesc, cnmcNumSerie, cnmcFournisseur, cnmcFactureFournisseur, cnmcFacture, cnmcDateFinGarantie} EColMaterielsClient;
		enum {ctncId, ctncNom, ctncTaux, ctncCompteComptable} EColTvaName;
		enum {etnAction, etnContacts, etnAdresses, etnDevis, etnCommandes, etnBLs, etnFacture, etnPrix, etnDocs, etnEcheance, etnMat, etnTva, etnCommentaires} ETabName;
		
		CGlobal::EAction actionCur;
		QString mailTemplate;
		CGrilleWidget *actionWidget;
		CGrilleWidget *contactWidget;
		CGrilleWidget *adressesWidget;
		CGrilleWidget *devisWidget;
		CGrilleWidget *commandesWidget;
		CGrilleWidget *blsWidget;
		CGrilleWidget *facturesWidget;
		CGrilleWidget *prixArticleWidget;
		CGrilleWidget *documentsWidget;
		CGrilleWidget *echeancesWidget;
		CGrilleWidget *materielsWidget;
		CGrilleWidget *tvaWidget;
		CTextRevWidget *cmtrsWidget;
		CMainFrm *mainFrm;
		QMenu *popupMenu;
		QMenu *favorisMenu;
		int curContactNum;
		QAction *actActionFromContact;
		QAction *actMailFromContact;
		QAction *actNouveauFavoris;
		QAction *actGestFavoris;
		QAction *actSeparator;
		bool responsableModif;
		bool cmtrsChange;
	
		void setActionCur(CGlobal::EAction action);
		CGlobal::EAction getActionCur(void); 
		void closeEvent(QCloseEvent * event);
		void loadProspectInfo(QString codeProspect);
		void createGrilleActions(void);
		void loadGrilleActions(void);
		void createGrilleContact(void);
		void loadGrilleContact(void);
		void createGrilleAdresses(void);
		void loadGrilleAdresses(void);
		void createGrilleDevis(void);
		void loadGrilleDevis(void);
		void createGrilleCommandes(void);
		void loadGrilleCommandes(void);
		void createGrilleBLs(void);
		void loadGrilleBLs(void);
		void createGrilleFactures(void);
		void loadGrilleFactures(void);
		void createGrillePrixArticle(void);
		void loadGrillePrixArticle(void);
		void createGrilleDocuments(void);
		void loadGrilleDocuments(void);
		void createGrilleEcheances(void);
		void loadGrilleEcheances(void);
		void createGrilleMateriels(void);
		void loadGrilleMateriels(void);
		void createGrilleTva(void);
		void loadGrilleTva(void);
		void creerDocument(int row);
		void makeMenu(void);
		void loadFavoris(QMenu *menu, int *parent=0);
		void loadActionInfo(QString action, int row);
		void dropFavoris(QMenu *menu);
		void makeRequete(QString &requete, QString &alias);
		void showFormulaire(QSqlQuery *query, CGlobal::EAction& action);
		void loadCommentaires(void);
		int makeCommentaires(QString &cmtrs, int revision=0);
	private slots:
		void on_actAjouter_triggered(void);
		void on_actValider_triggered(void);
		void on_actAnnuler_triggered(void);
		void on_actProspect_triggered(void);
		void on_actSupprimer_triggered(void);
		void onChange(void);
		void onCmtrsChange(void);
		void on_actRechercheUneFiche_triggered(void);
		void on_actEvolution_triggered(void);
		void on_actAbonneEMailing_triggered(void);
		void onCombo(CMyComboBox *comboBox);
		void onMailTo(QString href);
		void ajouteAction(bool &goToLast, int numContact=-1);
		void supprimeAction(int row, bool& ok);
		void modifiAction(int row, int column);
		void actionDoubleClicked(int row, int column);
		void ajouteContact(bool &goToLast);
		void supprimeContact(int row, bool& ok);
		void modifiContact(int row, int column);
		void contactDoubleClicked(int row, int column);
		void ajouteAdresse(bool &goToLast);
		void supprimeAdresse(int row, bool& ok);
		void modifiAdresse(int row, int column);
		void adresseDoubleClicked(int row, int column);
		void devisDoubleClicked(int row, int column);
		void commandesDoubleClicked(int row, int column);
		void blsDoubleClicked(int row, int column);
		void facturesDoubleClicked(int row, int column);
		void ajoutePrixArticle(bool &goToLast);
		void supprimePrixArticle(int row, bool& ok);
		void modifiPrixArticle(int row, int column);
		void lignePrixArticleDoubleClicked(int row, int column);
		void ajouteDocument(bool &goToLast);
		void supprimeDocument(int row, bool& ok);
		void modifiDocument(int row, int column);
		void documentDoubleClicked(int row, int column);
		void ajouteEcheance(bool &goToLast);
		void supprimeEcheance(int row, bool& ok);
		void modifiEcheance(int row, int column);
		void echeanceDoubleClicked(int row, int column);
		void tableCustomContextMenuRequested(const QPoint & pos);
		void actActionFromContact_triggered(void);
		void actMailFromContact_triggered(void);
		void ajouteMateriel(bool &goToLast);
		void supprimeMateriel(int row, bool& ok);
		void modifiMateriel(int row, int column);
		void materielDoubleClicked(int row, int column);
		void onInvokeHelp(CChamp *champ);
		void on_actFavorisClient_triggered(void);
		void actNouveauFavoris_triggered(void);
		void actGestFavoris_triggered(void);
		void actSelectFavoris_triggered(void);
		void on_actEcheancier_triggered(void);
		void onResponsableChange(void);
		void beforeInsertAction(const QSqlQuery *query, CMyTableWidgetItem *item);
		void beforeChangeRecordContact(const QSqlQuery *query, int row);
		void onLoadCmtrsRevision(QString revision);
		void modifiTva(int row, int column);
};
//------------------------------------------------------------------------------
#endif //__CCLIENTFRM_H__
//------------------------------------------------------------------------------
